using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Xml;
using System.IO;

namespace T4Airline
{
	class WeatherData
	{
		public static string place { get; set; }
		public static string obs_time { get; set; }
		public static string weather1 { get; set; }
		public static string temperature_string { get; set; }
		public static string relative_humidity { get; set; }
		public static string wind_string { get; set; }
		public static string pressure_mb { get; set; }
		public static string dewpoint_string { get; set; }
		public static string visibility_km { get; set; }
		public static string longitude { get; set; }
		public static string latitude { get; set; }
		public static string precip_today_string { get; set; }

		public WeatherData() { }
		public string parse(string input_xml)
		{
			//Variables
			place = "";
			obs_time = "";
			weather1 = "";
			temperature_string = "";
			relative_humidity = "";
			wind_string = "";
			pressure_mb = "";
			dewpoint_string = "";
			visibility_km = "";
			latitude = "";
			longitude = "";
			precip_today_string = "";


			var cli = new WebClient();
			string weather = cli.DownloadString(input_xml);

			using (XmlReader reader = XmlReader.Create(new StringReader(weather)))
			{
				// Parse the file and display each of the nodes.
				while (reader.Read())
				{
					switch (reader.NodeType)
					{
						case XmlNodeType.Element:
							if (reader.Name.Equals("full"))
							{
								reader.Read();
								place = reader.Value;
							}
							else if (reader.Name.Equals("observation_time"))
							{
								reader.Read();
								obs_time = reader.Value;
							}
							else if (reader.Name.Equals("weather"))
							{
								reader.Read();
								weather1 = reader.Value;
							}
							else if (reader.Name.Equals("temperature_string"))
							{
								reader.Read();
								temperature_string = reader.Value;
							}
							else if (reader.Name.Equals("relative_humidity"))
							{
								reader.Read();
								relative_humidity = reader.Value;
							}
							else if (reader.Name.Equals("wind_string"))
							{
								reader.Read();
								wind_string = reader.Value;
							}
							else if (reader.Name.Equals("pressure_mb"))
							{
								reader.Read();
								pressure_mb = reader.Value;
							}
							else if (reader.Name.Equals("dewpoint_string"))
							{
								reader.Read();
								dewpoint_string = reader.Value;
							}
							else if (reader.Name.Equals("visibility_km"))
							{
								reader.Read();
								visibility_km = reader.Value;
							}
							else if (reader.Name.Equals("latitude"))
							{
								reader.Read();
								latitude = reader.Value;

							}
							else if (reader.Name.Equals("longitude"))
							{
								reader.Read();
								longitude = reader.Value;
							}
							else if (reader.Name.Equals("precip_today_string"))
							{
								reader.Read();
								precip_today_string = reader.Value;
							}
							break;
					}
				}
			}
			/*Console.WriteLine("********************");
			Console.WriteLine("Place:             " + place);
			Console.WriteLine("Observation Time:  " + obs_time);
			Console.WriteLine("Weather:           " + weather1);
			Console.WriteLine("Temperature:       " + temperature_string);
			Console.WriteLine("Relative Humidity: " + relative_humidity);
			Console.WriteLine("Wind:              " + wind_string);
			Console.WriteLine("Pressure (mb):     " + pressure_mb);
			Console.WriteLine("Dewpoint:          " + dewpoint_string);
			Console.WriteLine("Visibility (km):   " + visibility_km);
			Console.WriteLine("Location:          " + longitude + ", " + latitude);
			Console.WriteLine("Precipitation:     " + precip_today_string);
			Console.WriteLine("");*/

			return "";
		}
	}
}
